package com.example.springboot.web;

import com.example.springboot.mapper.AdveMapper;
import com.example.springboot.mapper.BbsMapper;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;

@Controller
public class IndexAction {

    @Resource
    BbsMapper bm;

    @Resource
    AdveMapper am;

    @GetMapping("/")
    public String index(Model model){
        model.addAttribute("blist",bm.selectTop());
        model.addAttribute("alist",am.selectTop5());
        return "index";
        // 视图路径解析过程 : 视图前缀  + 视图名  + 后缀
        // classpath:/templates/ + index + .html
        // ==> /templates/index.html
    }

    @GetMapping("/bbsShow")
    public String bbsShow(int id, Model model){
        model.addAttribute("bbs",bm.selectById(id));
        return "bbs_show";
    }
}
